class Solution:
    def fractionToDecimal(self, numerator: int, denominator: int) -> str:
        if numerator * denominator < 0:
            res, numerator = "-", -numerator
        else:
            res = ""
        int_part, yu_part = str(numerator // denominator), numerator % denominator
        yu_dic, i, decim_list = {}, 0, []
        while yu_part != 0 and yu_part not in yu_dic:
            yu_dic[yu_part] = i
            i += 1
            decim_list.append(str((yu_part * 10) // denominator))
            yu_part = (yu_part * 10) % denominator
        if yu_part != 0:
            decim_list.insert(yu_dic[yu_part], "(")
            decim_list.append(")")
            res += int_part + "." + "".join(decim_list)
        else:
            if decim_list:
                res += int_part + "." + "".join(decim_list)
            else:
                res += int_part
        return res


a = Solution()
print(a.fractionToDecimal(1, 2))
print(a.fractionToDecimal(2, 1))
print(a.fractionToDecimal(2, 3))
print(a.fractionToDecimal(4, 333))
print(a.fractionToDecimal(1, 333))
print(a.fractionToDecimal(1, 214748364))
print(a.fractionToDecimal(0, 3))
print(a.fractionToDecimal(-22, -1))
print(a.fractionToDecimal(-7, 12))
print(a.fractionToDecimal(-1, -2147483648))
